package com.accp.demo.service.purchase;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.accp.demo.mapper.pruchase.IPurchaseOutStorageMapper;
import com.accp.demo.pojo.PageBean;
import com.accp.demo.pojo.purchase.PurchaseOutStorage;


//采购退货
@Service
public class PurchaseOutStorageService {

	@Autowired
	private IPurchaseOutStorageMapper purchaseOutStorageMapper;

	/**
	 * 新增采购退货单
	 * 
	 * @param pojo
	 */
	public void insert(PurchaseOutStorage pojo) {
		purchaseOutStorageMapper.insert(pojo);
	};

	/**
	 * 修改采购退货单
	 * 
	 * @param pojo
	 */
	public void update(PurchaseOutStorage pojo) {
		purchaseOutStorageMapper.update(pojo);
	};

	/**
	 * 删除采购退货单(改变单据的逻辑状态)
	 * 
	 * @param billNo
	 */
	public void delete(String billNo, Integer logicState) {
		purchaseOutStorageMapper.delete(billNo, logicState);
	};

	/**
	 * 审核采购退货单
	 * 
	 * @param billNo
	 * @param auditingState
	 */
	public void updateAuditingState(String billNo, Integer auditingState) {
		purchaseOutStorageMapper.updateAuditingState(billNo, auditingState);
	};

	/**
	 * 查询采购退货单
	 * 
	 * @return
	 */
	public PageBean query(Map<String, Object> map) {
		int currPage = Integer.valueOf(String.valueOf(map.get("page")));
		int pageSize = Integer.valueOf(String.valueOf(map.get("limit")));
//		System.out.println("查的是第" + currPage + "页" + "，这一页有" + pageSize + "条记录！");
		int count = purchaseOutStorageMapper.getCount();
		List<PurchaseOutStorage> data = purchaseOutStorageMapper.query((currPage - 1) * pageSize, pageSize);
		data.get(0).getPurchaseOutStorageInfos().get(0).setBillNo("");
		PageBean pb = new PageBean(count, pageSize, currPage, data);
		return pb;
	};

	/**
	 * 查询采购退货单的总行数
	 * 
	 * @return
	 */
	public Integer getCount() {
		return purchaseOutStorageMapper.getCount();
	};
	
	/**
	 * 选择重新入库（由采购订单转入）修改采购订单中的未采购数量、订单单况
	 * @param fromNo
	 * @param poDk
	 * @param podNoCount
	 */
	public void updateOrderPodNoCountAndPoDk(String fromNo,int poDk,int podNoCount){
		purchaseOutStorageMapper.updateOrderPodNoCountAndPoDk(fromNo, poDk, podNoCount);
	};
}
